# Strategy: 'Nicer Than Most'
# Author: Brian Kirst
# Description: In my experience, simple solutions are usually the best.
# My strategy will be to roughly stay in the top half of helpful hunters, while helping the other most helpful hunters.
# Since identities are unknown, tit-for-tat can't be precisely implemented, although it is probably the optimal solution.
# This strategy assumes that other winning strategies will be various implementations of tit-for-tat.
# This strategy is extremely vulnerable to backstabbing by players with high reputations. 
# Fortunately, I do not believe backstabbing will be a viable long term strategy.

def hunt_choices(round_number, current_food, current_reputation, m,  player_reputations):   
    # Just help everyone for the first two (three?) rounds to establish rep
    if (round_number>2):

        # Get sorted list of values so we can determine statistics
        # sorted_player_reps = sorted(player_reputations);
        sorted_player_reps = list(player_reputations);
        sorted_player_reps.sort(reverse=True);
        
        # Get median value
        median_value = sorted_player_reps[(len(player_reputations)-1)/2];
        
        # The median rep will be my rep for this round if I help everyone above 'median_hunt'
        median_hunt = sorted_player_reps[int((len(player_reputations)-1)*(median_value))]
        median_hunt_index = int((len(player_reputations)-1)*(median_value));
        
        # Find out how many people we will hunt with if we hunt with everyone over 50%
        i = 0;
        for x in sorted_player_reps:
            if (x>=.50):
                i = i + 1;
        fifty_percent_hunt_index = i-1;
    
        # Hunt with everyone who has a rep of 50% or higher.
        # If the median player has hunted more than I would if i hunted with everyone over 50%,
        # then hunt as much as he has.
        if (fifty_percent_hunt_index >= median_hunt_index) :
            threshold_value = .50;
        else :
            threshold_value = sorted_player_reps[median_hunt_index];
        
        hunt_decisions = [];
        for x in player_reputations:
            if (x>=threshold_value):
                hunt_decisions.append('h');
            else:
                hunt_decisions.append('s');
    else:
        hunt_decisions = ['h' for x in player_reputations];

    return hunt_decisions;

def hunt_outcomes(food_earnings):
    # Theoretically I could try to track hunt outcomes based on the previous and new %'s
    # I would bet that's what a winning strategy will base their tit for tat on
    # But I'm going to go simpler and ignore these outcome methods
    pass 

def round_end(award, m, number_hunters):
    pass